from classifier.classifier import Classifier
from sklearn.svm import SVC


# 支持向量机
class SVM(Classifier):
    # 核函数
    kernel = "rbf"
    
    def __init__(self):
        Classifier.__init__(self)
        self.algorithm_name = "支持向量机"
        self.ipynb_template_name = "svm-template.ipynb"
        
    def implent(self): 
        Classifier.implent(self)
        # 构造模型
        self.algorithm = SVC(kernel=self.kernel, probability=True)
        # 训练模型
        self.algorithm.fit(self.train_inputs, self.train_outputs)
        # 评估模型
        self.score = self.algorithm.score(self.test_inputs, self.test_outputs)
        # 预测
        self.predict_output_values = self.algorithm.predict(self.predict_input_values)
        self.predict_output_probas = self.algorithm.predict_proba(self.predict_input_values)
    
    def prepareIpynbItems(self):
        Classifier.prepareIpynbItems(self)
        self.ipynb_items["#kernel#"] = self.kernel
